//
//  Notification+YHExtension.swift
//  Adorbee
//
//  Created by amovision on 2024/11/28.
//

import Foundation
#if canImport(YYKit)
import YYKit
#endif

public extension Notification.Name {
  static let networkChanged = Notification.Name("YHKitNetworkChangedNotification")
}

public extension NSObject {
  func addNotification<T>(_ name: Notification.Name, type: T.Type, usingBlock: @escaping (T?) -> Void) {
#if canImport(YYKit)
    addNotification(withName: name, object: nil) { note in
      usingBlock(note.object as? T)
    }
#endif
  }

  func addNotification(_ name: Notification.Name, object: Any? = nil, usingBlock: @escaping ([AnyHashable: Any]?, Any?) -> Void) {
#if canImport(YYKit)
    addNotification(withName: name, object: object) { note in
      usingBlock(note.userInfo, note.object)
    }
#endif
  }

#if !canImport(YYKit)
  func removeNotifications() {}
#endif
}
